<template>
  <div class="content">
    <div class="content-top">
      <el-row :gutter="20">
        <el-col :span="18">
          <div class="content-top-list">
            <span class="content-top-bg1" @click="jump(1)" @mouseleave="bgShow = 0">
              <h1>中心简介</h1>
              <p>国家、省级产业计量测试中心简介</p>
              <span class="content-top-bg-color" v-show="bgShow == 1"> </span>
            </span>

            <span class="content-top-bg2" @click="jump(2)">
              <h1>供需对接</h1>
              <p>计量测试需求对接</p>
            </span>
            <span class="content-top-bg6" @click="jump(6)">
              <h1>联盟链网</h1>
              <p>计量测试服务资源网络</p>
            </span>
          </div>
        </el-col>
        <el-col :span="6">
          <div class="content-top-list content-top-list2">
            <div class="content-top-bg3" @click="jump(3)">
              <h1 class="h1-bottom">科技社群</h1>
              <i class="arrow-right-icon"></i>
            </div>
            <div class="content-top-bg4" @click="jump(4)">
              <h1 class="h1-bottom">会议培训</h1>
              <i class="arrow-right-icon"></i>
            </div>
            <div class="content-top-bg5" @click="jump(5)">
              <h1 class="h1-bottom">典型案例</h1>
              <i class="arrow-right-icon"></i>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>
    <div class="content-news">
      <div class="content-news-block">
        <div class="content-news-header">
          <div class="news-list-main">
            <div class="news-list-left" v-if="newsList.length > 0" @click="jumpNews(newsList[0])">
              <img width="580" height="320" :src="newsList[0].articlePicture" />
              <div class="news-overlay">
                <div class="news-title">{{ newsList[0].title }}</div>
              </div>
            </div>
            <div class="news-list-right">
              <div class="news-header-info">
                <span class="header-title">新闻资讯</span>
                <span class="header-more" @click="jump(7)">查看更多 »</span>
              </div>
              <div
                class="news-item"
                v-for="(item, index) in newsList.slice(1)"
                :key="item.articleAbstract"
                @click="jumpNews(item)"
              >
                <div class="news-title">{{ item.title }}</div>
                <div class="news-time">{{ item.createTime }}</div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="content-info">
      <div class="content-info-block">
        <h1 class="info-block-title">上年度供需对接开展情况</h1>
        <div class="info-list">
          <div class="info-list-item" v-for="item in infoList" :key="item.name">
            <div class="info-list-item-name">{{ item.name }}</div>
            <div class="info-list-item-value">
              {{ item.value }}
              <span>
                {{ item.unit }}
              </span>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="statistics">
      <div class="statistics-top">
        <div class="statistics-top-title">
          <span class="statistics-title">长三角中心分布情况</span>
          <i class="statistics-icon"></i>
        </div>
        <div class="statistics-top-charts">
          <div>
            <echart
              :options="mainChartOption"
              style="height: 300px; width: 800px"
              v-if="chartOption"
            ></echart>
          </div>
          <echart
            :options="chartOption"
            class="word-chart"
            v-if="chartOption"
            style="width: 400px; height: 300px"
          ></echart>
        </div>
      </div>
      <div class="statistics-bottom">
        <div
          class="statistics-bottom-item"
          :class="`statistics-bottom-bg${index + 1}`"
          v-for="(item, index) in statisticsList"
          :key="item.name"
        >
          <div class="statistics-bottom-item-title" v-html="item.name"></div>
          <div class="statistics-bottom-item-value">
            {{ item.value }}
            <span class="statistics-bottom-item-unit">{{ item.unit }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup>
import { cmsArticle } from '@/api'
import { Echart } from '@/components/Echart'

// 获取并store所有字典数据，供全局使用
// const store = useStore()
// store.dispatch('fetchDictionary')

const bgShow = ref(0)
const router = useRouter()

function jump(val) {
  switch (val) {
    case 1:
      router.push('/centerIntroductory')
      break
    case 2:
      router.push('/requirementSolution')
      break
    case 3:
      router.push('/technologyAssociation')
      break
    case 4:
      router.push('/conferenceTraining')
      break
    case 5:
      router.push('/typicalCase')
      break
    case 6:
      router.push('/unitMap')
      break
    case 7:
      router.push('/news')
      break
    default:
      break
  }
}

function jumpNews(item) {
  router.push({ path: '/newsDetails', query: { id: item.id } })
}
const newsList = ref([])
const infoList = ref([
  { name: '需求企业', value: '430', unit: '家' },
  { name: '需求数', value: '532', unit: '个' },
  { name: '方案数', value: '620', unit: '个' },
  { name: '预算总额(万元 )', value: '18398.2', unit: '' },
  { name: '资金投入(万元)', value: '18398.2', unit: '' }
  //{ name: '对接数', value: "/", unit: "个" },
])
const statisticsList = ref([
  { name: '国家产业<br/>计量测试中心', value: '18', unit: '家' },
  { name: '省(市)级产业<br/>计量测试中心', value: '34', unit: '家' },
  { name: '核心企业', value: '2448', unit: '家' },
  { name: '会议培训', value: '3', unit: '家' },
  { name: '科技成果', value: '15', unit: '家' },
  { name: '产业需求', value: '225', unit: '家' }
])
const fruits = ref([
  { name: '互联网服务', value: 1000 },
  { name: '交通运输', value: 850 },
  { name: '公司', value: 800 },
  { name: '军工', value: 600 },
  { name: '医药', value: 900 },
  { name: '商务服务', value: 600 },
  { name: '城乡规划', value: 800 },
  { name: '家政服务', value: 400 },
  { name: '安防', value: 850 },
  { name: '医疗服务', value: 200 },
  { name: '电子科技', value: 8000 },
  { name: '航空航天', value: 1500 },
  { name: '食品饮料', value: 1500 },
  { name: '能源', value: 800 },
  { name: '教育培训', value: 200 },
  { name: '金融', value: 100 },
  { name: '文化娱乐', value: 250 },
  { name: '电力', value: 1200 },
  { name: '石油化工', value: 300 },
  { name: '电子商务', value: 900 },
  { name: '建筑', value: 700 },
  { name: '旅游', value: 550 },
  { name: '环保', value: 750 },
  { name: '地产', value: 1100 },
  { name: '体育', value: 300 },
  { name: '通信', value: 950 },
  { name: '科研', value: 1200 },
  { name: '物流', value: 1300 },
  { name: '咨询', value: 600 }
])
const chartOption = ref(null)
const mainChartOption = ref(null)
function initCharts() {
  chartOption.value = {
    grid: {
      left: '5%',
      right: '5%',
      bottom: '5%',
      top: '5%',
      containLabel: true
    },
    series: [
      {
        type: 'wordCloud',
        gridSize: 12, // 控制词云图的网格大小，值越大词语之间的间距越大
        sizeRange: [10, 80], // 控制词语的大小范围
        rotationRange: [30, 0], // 控制词语的旋转角度范围
        rotationStep: 45, // 控制词语旋转的步长
        shape: 'diamond', // 控制词云图的形状，可选值为 'circle', 'cardioid', 'diamond', 'triangle-forward', 'triangle', 'pentagon', 'star'
        drawOutOfBound: false, // 控制词云图是否允许词语超出绘制区域
        // 布局的时候是否有动画
        layoutAnimation: true,
        // 图的位置
        left: 'center',
        top: 'center',
        textStyle: {
          fontFamily: 'sans-serif',
          color: function () {
            return (
              'rgb(' +
              [
                Math.round(Math.random() * 160),
                Math.round(Math.random() * 160),
                Math.round(Math.random() * 160)
              ].join(',') +
              ')'
            )
          }
        },
        data: fruits.value,
        emphasis: {
          focus: 'self',
          textStyle: {
            fontSize: 20 // 点击的词放大
          }
        }
      }
    ]
  }
  mainChartOption.value = {
    tooltip: {
      trigger: 'axis'
    },
    legend: {
      top: '5%',
      data: ['国家产业计量测试中心', '省(市)级产业计量测试中心', '中心总数']
    },
    xAxis: [
      {
        type: 'category',
        data: ['长三角', '上海', '江苏', '浙江', '安徽']
      }
    ],
    yAxis: [
      {
        type: 'value',
        show: false
      }
    ],
    series: [
      {
        name: '国家产业计量测试中心',
        type: 'bar',
        tooltip: {
          valueFormatter: function (value) {
            return value
          }
        },
        data: [18, 6, 7, 4, 1]
      },
      {
        name: '省(市)级产业计量测试中心',
        type: 'bar',
        tooltip: {
          valueFormatter: function (value) {
            return value
          }
        },
        data: [34, 9, 13, 7, 5]
      },
      {
        name: '中心总数',
        type: 'bar',
        tooltip: {
          valueFormatter: function (value) {
            return value
          }
        },
        data: [52, 15, 20, 11, 6]
      }
    ]
  }
}

function getList() {
  cmsArticle({
    articleType$Contains: 'NS', //科普知识
    pageSize: 7,
    pageNum: 1
  }).then((res) => {
    if (res.code == '0') {
      newsList.value = res.data.list
    }
  })
}

onMounted(() => {
  initCharts()
  getList()
})
</script>
<style lang="scss" scoped>
.content {
  //width: 100%;
  //height: 1880px;
  padding-bottom: 40px;

  .content-top {
    width: 1200px;
    margin: auto;
    margin-top: 50px;

    .content-top-list {
      display: flex;
      justify-content: space-between;
      margin: 20px 0;

      .content-top-bg-color {
        position: absolute;
        top: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(35, 103, 239, 0.6);
      }

      .content-top-bg1 {
        position: relative;
        width: 285px;
        background: url('@/assets/images/content-top-bg1.png') no-repeat;
        background-size: 100% 100%;
        cursor: pointer;
      }

      .content-top-bg2 {
        width: 285px;
        height: 460px;
        background: url('@/assets/images/content-top-bg2.png') no-repeat;
        background-size: 100% 100%;
        cursor: pointer;
      }

      .content-top-bg6 {
        width: 285px;
        height: 460px;
        background: url('@/assets/images/content-top-bg6.png') no-repeat;
        background-size: 100% 100%;
        cursor: pointer;
      }

      h1 {
        margin: 60px 0 0 30px;
        font-weight: 500;
        font-size: 24px;
        font-family: PingFang SC, PingFang SC !important;
        color: #fff;
      }

      p {
        margin: 20px 0 0 20px;
        font-size: 16px;
        color: #fff;
      }

      .h1-bottom {
        margin-top: 0;
      }

      .content-top-bg3 {
        width: 100%;
        height: 140px;
        padding-top: 30px;
        background: url('@/assets/images/content-top-bg3.png') no-repeat;
        background-size: 100% 100%;
        cursor: pointer;
      }

      .content-top-bg4 {
        width: 100%;
        height: 140px;
        padding-top: 30px;
        margin: 20px 0;
        background: url('@/assets/images/content-top-bg4.png') no-repeat;
        background-size: 100% 100%;
        cursor: pointer;
      }

      .content-top-bg5 {
        width: 100%;
        height: 140px;
        padding-top: 30px;
        background: url('@/assets/images/content-top-bg5.png') no-repeat;
        background-size: 100% 100%;
        cursor: pointer;
      }

      .arrow-right-icon {
        display: inline-block;
        width: 42px;
        height: 20px;
        margin: 15px 0 0 30px;
        background: url('@/assets/images/icon/arrow-right-icon.png') no-repeat;
        background-size: 100% 100%;
      }
    }

    .content-top-list2 {
      display: block;
    }
  }

  // .content-news {
  //   width: 100%;
  //   padding-top: 40px;
  //   padding-bottom: 30px;
  //   background: url('@/assets/images/new-bg.png') no-repeat;
  //   background-size: 100% 100%;

  //   .content-news-block {
  //   }

  //   .content-news-carousel {
  //     width: 40%;
  //     margin-right: 20px;
  //   }

  //   .el-carousel__item:nth-child(2n) {
  //     background-color: #99a9bf;
  //   }

  //   .el-carousel__item:nth-child(2n + 1) {
  //     background-color: #d3dce6;
  //   }

  //   .content-news-header {
  //     .news-more {
  //       display: flex;
  //       justify-content: center;
  //       margin-top: 30px;

  //       .header-more {
  //         display: flex;
  //         align-items: center;
  //         justify-content: center;
  //         width: 100px;
  //         height: 30px;
  //         font-size: 16px;
  //         background-color: #fff;
  //         border: 1px solid #d5d7d7;
  //         color: #333;
  //         cursor: pointer;
  //       }
  //     }

  //     .news-header-info {
  //       display: flex;
  //       justify-content: center;
  //       align-items: center;
  //       height: 80px;

  //       .header-title {
  //         font-size: 26px;
  //         color: #333333;
  //       }
  //     }

  //     .news-list-main {
  //       display: flex;
  //       justify-content: center;
  //       width: 1200px;
  //       margin: auto;
  //     }

  //     .news-list {
  //       margin-right: 20px;
  //       background-color: #fff;
  //       cursor: pointer;

  //       .news-title {
  //         margin: 20px;
  //         color: #333333;
  //       }

  //       .news-time {
  //         margin: 20px;
  //         font-size: 13px;
  //         color: #bbbbbb;
  //       }
  //     }

  //     .news-header-list {
  //       display: flex;
  //       flex-wrap: wrap;
  //     }
  //   }
  // }
  .content-news {
    width: 1200px;
    margin: 30px auto;
    .news-list-main {
      display: flex;
      gap: 30px;
    }

    .news-list-left {
      flex: 0 0 580px;
      position: relative;
      cursor: pointer;
      overflow: hidden;

      img {
        width: 100%;
        height: 320px;
        object-fit: cover;
        transition: transform 0.3s;
      }

      &:hover img {
        transform: scale(1.05);
      }

      .news-overlay {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        padding: 10px;
        background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
        color: white;

        .news-title {
          font-size: 18px;
          line-height: 1.4;
          margin-bottom: 10px;
        }
      }
    }

    .news-list-right {
      flex: 1;
      display: flex;
      flex-direction: column;

      .news-header-info {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 20px;

        .header-title {
          font-size: 20px;
          font-weight: bold;
        }

        .header-more {
          color: #409eff;
          cursor: pointer;
        }
      }

      .news-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 12px 0;
        cursor: pointer;
        border-bottom: 1px solid #eee;

        &:first-child {
          padding-top: 0;
        }

        &:hover {
          .news-title {
            color: #409eff;
          }
        }

        .news-title {
          flex: 1;
          font-size: 16px;
          margin-right: 20px;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
          transition: color 0.3s;
        }

        .news-time {
          color: #999;
          font-size: 14px;
        }
      }
    }
  }
  .content-info {
    width: 100%;
    height: 300px;
    padding-top: 40px;
    background: url('@/assets/images/info-bg.png') no-repeat;
    background-size: 100% 100%;

    .content-info-block {
      width: 1200px;
      margin: auto;
      color: #fff;

      .info-block-title {
        margin-bottom: 50px;
        text-align: center;
        font-size: 28px;
        font-weight: 500;
      }

      .info-list {
        display: flex;
        justify-content: space-between;

        .info-list-item {
          .info-list-item-name {
            font-size: 22px;
          }

          .info-list-item-value {
            font-family: Bebas, Bebas;
            margin-top: 10px;
            font-size: 60px;

            span {
              font-size: 14px;
            }
          }
        }
      }
    }
  }

  .statistics {
    width: 1200px;
    margin: 30px auto;

    .statistics-top {
      height: 340px;
      padding: 10px 20px;
      box-shadow: 0px 1px 10px 0px #dbe2eb;

      .statistics-top-title {
        display: flex;
        justify-content: space-between;
        align-items: center;
        height: 50px;
        border-bottom: 1px solid #e2e4e7;
        font-size: 20px;

        .statistics-icon {
          display: inline-block;
          width: 120px;
          height: 30px;
          background: url('@/assets/images/statistics-icon.png') no-repeat;
          background-size: 100% 100%;
        }
      }

      .statistics-top-charts {
        display: flex;
      }

      .statistics-top-content {
        height: 290px;
        padding: 10px 0;
        display: flex;
        justify-content: space-between;

        .statistics-top-content-item {
          width: 33.33%;
          height: 100%;
          border-right: 1px solid #cfd2d5;

          .statistics-top-content-item-title {
            font-size: 16px;
            text-align: center;
          }
        }
      }
    }

    .statistics-bottom {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-top: 30px;

      .statistics-bottom-item {
        width: 200px;
        height: 140px;
        padding: 20px 0;
        text-align: center;
        font-size: 22px;
        color: #fff;

        .statistics-bottom-item-title {
          padding: 0 10px;
          height: 60px;
          width: 100%;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          display: flex;
          align-items: center;
          justify-content: center;
          text-align: center;
        }

        .statistics-bottom-item-value {
          margin-top: 10px;
          font-size: 36px;
        }

        .statistics-bottom-item-unit {
          font-size: 14px;
        }
      }

      .statistics-bottom-bg1 {
        background: url('@/assets/images/statistics-bottom-bg1.png') no-repeat;
        background-size: 100% 100%;
      }

      .statistics-bottom-bg2 {
        background: url('@/assets/images/statistics-bottom-bg2.png') no-repeat;
        background-size: 100% 100%;
      }

      .statistics-bottom-bg3 {
        background: url('@/assets/images/statistics-bottom-bg3.png') no-repeat;
        background-size: 100% 100%;
      }

      .statistics-bottom-bg4 {
        background: url('@/assets/images/statistics-bottom-bg4.png') no-repeat;
        background-size: 100% 100%;
      }

      .statistics-bottom-bg5 {
        background: url('@/assets/images/statistics-bottom-bg5.png') no-repeat;
        background-size: 100% 100%;
      }

      .statistics-bottom-bg6 {
        background: url('@/assets/images/statistics-bottom-bg6.png') no-repeat;
        background-size: 100% 100%;
      }
    }
  }
}
</style>
